import {ElMessage} from "element-plus";

export const downloadFile = async(fileurl, filename)=>{
    try {
        const response = await fetch(`http://localhost:8080/api/file/downloadfile?FileUrl=${fileurl}`);
        if (!response.ok) {
            throw new Error('文件下载失败');
        }
        const blob = await response.blob();
        const url = window.URL.createObjectURL(blob);

        const a = document.createElement('a');
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        window.URL.revokeObjectURL(url);
    } catch (error) {
        console.log(error)
        ElMessage.error('文件下载失败');
    }
}
